<template>
  <page-meta :root-font-size="fontsize" style="display: block">
    <div class="topRecruitment">
      <xlNavBar :isShare="isShare" title="置顶招聘" bgc="transparent"></xlNavBar>
      <image src="https://canyinxinxi.cn/dist_img/WechatIMG5143.jpg" class="bgi" />
      <image src="https://canyinxinxi.cn/dist_img/46_1681739440583459967.vAL3xysZyTgg8bd86da11d5201dd3d7f2054db952a07.png" class="image" mode="aspectFill" />
      <div class="content">
        <div class="select_city_wrap">
          <div class="title_wrap">
            <text class="t_title">选择置顶时间（单选）</text>
            <text class="s_title">{{ dueTime }}到期</text>
          </div>
          <div class="radio_wrap">
            <div @click="clickItem(item)" class="item" :class="[date == item.value ? 'active' : '']" v-for="(item, index) in radiolist1" :key="index">
              <span>{{ item.name }}</span>
              <image v-if="date == item.value" class="image" src="/pages2/static/images/radioActive.png" mode="scaleToFill" />
            </div>
          </div>
        </div>
        <div class="zdgz">
          <div class="title">置顶规则</div>
          <div class="content_p">
            <p class="p">1.每天需消耗3积分，总消耗=天数*3积分</p>
            <p class="p">2.如有任何疑问欢迎联系餐饮信息网客服</p>
          </div>
        </div>
      </div>
      <footer class="footer">
        <div class="left">
          共需
          <text class="num">{{ num }}</text>
          积分
        </div>
        <div class="right" @click="qrzd">确认置顶</div>
      </footer>
      <!-- 积分充值 -->
      <integral-recharge v-if="showJf" ref="recharge" :jfye="userInfo.integral" :hcjf="hcjf" :show="showJf" @close="showJf = false"></integral-recharge>
      <TopSuccess :show="showTopSuccess" :from="from"></TopSuccess>
    </div>
  </page-meta>
</template>

<script>
import PageFooter from "@/pages2/components/common/pageFooter.vue";
import IntegralRecharge from "@/pages2/components/popup/IntegralRecharge.vue";
import TopSuccess from "@/pages2/components/popup/TopSuccess.vue";
export default {
  name: "topRecruitment",
  components: { PageFooter, IntegralRecharge, TopSuccess },
  props: {},
  data() {
    return {
      isShare: 0,
      fontsize: "",
      code: "",
      cityList: ["上海，北京，深圳"],
      radiolist1: [
        {
          name: "1天（24小时）",
          value: 1,
          disabled: false,
        },
        {
          name: "2天",
          value: 2,
          disabled: false,
        },
        {
          name: "3天",
          value: 3,
          disabled: false,
        },
        {
          name: "7天",
          value: 7,
          disabled: false,
        },
        {
          name: "15天",
          value: 15,
          disabled: false,
        },
        {
          name: "30天",
          value: 30,
          disabled: false,
        },
      ],
      date: 1,
      userInfo: null,
      hcjf: 0,
      showJf: false,
      id: "",
      from: "add",
      showTopSuccess: false,
    };
  },
  computed: {
    num() {
      return this.date * 3;
    },
    dueTime() {
      let time = new Date().getTime() + this.date * 24 * 3600 * 1000;
      return this.$date.timestampToTime(time, 16);
    },
  },
  methods: {
    clickItem(item) {
      this.date = item.value; //将选中的值写入到data中的date变量中给date变量中的值
    },
    submitStatus() {
      this.$togo("/pages2/jobDetail", { id: this.id });
      this.showStattusPopup = false;
    },
    async qrzd() {
      let userInfo = await this.getUserIntegral();
      if (userInfo.integral < this.num) {
        this.showJf = true;
        this.hcjf = this.num - userInfo.integral;
      } else {
        let params = {
          user_id: this.$getStoraged("user_id") ? JSON.parse(this.$getStoraged("user_id")) : "",
          purpose_id: JSON.parse(this.id),
          type: 1,
          total_date: this.date,
          integral: this.num,
        };
        let res = await this.$http.requestSync("/campaigns/create", params);
        if (res.code == 200) {
          this.showTopSuccess = true;
        }
      }
    },
    // 获取用户详情（剩余积分）
    async getUserIntegral() {
      let _this = this;
      return new Promise(async resolve => {
        let res = await this.$http.requestSync("/user/info");
        if (res.code == 200) {
          _this.userInfo = res.data.user_info;
          this.$setStoraged("userInfo", res.data.user_info);
          resolve(res.data.user_info);
        }
      });
    },
  },
  // 页面周期函数--监听页面加载
  onLoad(options) {
    if (options.params) {
      let params = JSON.parse(decodeURIComponent(options.params));
      if (params.shareUserId) {
        this.$setStoraged("shareUserId", params.shareUserId);
        this.isShare = 1;
      }
    }
    if (options.id) {
      this.id = options.id;
    }
    if (options.from) {
      this.from = options.from;
    }
    let designWidth = 37.5; //因设计图的宽度
    let that = this;
    //窗体改变大小触发事件
    uni.onWindowResize(res => {
      console.log("变化后的窗口宽度=", res.size.windowWidth);
      //100*屏幕宽度/设计稿宽度
      that.fontsize = Math.floor((1.5 * res.size.windowWidth) / designWidth) + "px";
      console.log("字体大小：", that.fontsize);
    });

    //打开获取屏幕大小
    uni.getSystemInfo({
      success(res) {
        console.log("设备信息：", res);
        that.fontsize = Math.floor((1.5 * res.screenWidth) / designWidth) + "px";
        console.log("字体大小：", that.fontsize);
      },
    });
  },
  // 页面周期函数--监听页面初次渲染完成
  onReady() {},
  // 页面周期函数--监听页面显示(not-nvue)
  onShow() {},
  // 页面周期函数--监听页面隐藏
  onHide() {},
  // 页面周期函数--监听页面卸载
  onUnload() {},
  // 页面处理函数--监听用户下拉动作
  // onPullDownRefresh() { uni.stopPullDownRefresh(); },
  // 页面处理函数--监听用户上拉触底
  // onReachBottom() {},
  // 页面处理函数--监听页面滚动(not-nvue)
  // onPageScroll(event) {},
  // 页面处理函数--用户点击右上角分享
  // onShareAppMessage(options) {},
};
</script>

<style scoped lang="scss">
.topRecruitment {
  width: 100vw;
  .bgi {
    display: flex;
    align-items: center;
    width: 104%;
    height: 500px;
    padding: 0;
    position: fixed;
    top: -20px;
    left: -4%;
    z-index: -1;
  }
  .image {
    margin-top: 20px;
    width: 100%;
    height: 340px;
  }
  .content {
    width: 100%;
    background: linear-gradient(180deg, #fff5ed 0%, #f7f7f7 100%);
    border-radius: 14px 14px 0px 0px;
    display: table;
    position: relative;
    top: -50px;
    .select_city_wrap {
      width: 90%;
      // height: 97px;
      background: #ffffff;
      border-radius: 10px 10px 10px 10px;
      margin: 15px 18px 10px;
      .title_wrap {
        display: flex;
        justify-content: space-between;
        align-items: center;
        box-sizing: border-box;
        padding: 10px 18px;
        .t_title {
          font-size: 14px;
          font-family: PingFang SC-Semibold, PingFang SC;
          font-weight: 600;
          color: #333333;
        }
        .s_title {
          font-size: 12px;
          font-family: PingFang SC-Regular, PingFang SC;
          font-weight: 400;
          color: #999999;
        }
      }
      .ul {
        display: flex;
        width: 100%;
        box-sizing: border-box;
        padding: 10px 18px;
        .li {
          width: 78px;
          height: 32px;
          background: #f0f0f0;
          border-radius: 4px 4px 4px 4px;
          margin-right: 10px;
          font-size: 14px;
          font-family: PingFang SC-Regular, PingFang SC;
          font-weight: 400;
          color: #999999;
          text-align: center;
          line-height: 32px;
        }
        .active {
          color: #ffffff;
          background: #ff8822;
        }
      }
      /deep/.u-radio-group {
        display: flex;
        flex-wrap: wrap;
        margin: 0 auto;
        box-sizing: border-box;
        padding: 10px 18px;
        justify-content: space-around;
        .u-radio {
          width: 20%;

          font-family: PingFang SC-Regular, PingFang SC;
          font-weight: 400;
          color: #ff8822;
          .u-radio__text {
            font-size: 12px !important;
          }
        }
        .u-radio:nth-child(3n + 1) {
          width: 37%;
        }
      }
    }
    .zdgz {
      width: 100%;
      box-sizing: border-box;
      padding: 0 18px;
      margin: 12px auto;
      font-size: 12px;
      font-family: PingFang SC-Regular, PingFang SC;
      font-weight: 400;
      color: #999999;
      .content_p {
        margin-top: 8px;
        .p {
          height: 18px;
          line-height: 18px;
        }
      }
    }
    .radio_wrap {
      display: flex;
      width: 100%;
      flex-wrap: wrap;
      justify-content: space-between;
      box-sizing: border-box;
      padding: 0 18px;
      .item {
        width: 100px;
        height: 42px;
        background: #f6f6f6;
        border-radius: 5px 5px 5px 5px;
        font-size: 14px;
        font-weight: 400;
        color: #999999;
        text-align: center;
        line-height: 42px;
        margin-bottom: 12px;
        position: relative;
        .image {
          position: absolute;
          right: 0;
          bottom: 0px;
          width: 19px;
          height: 19px;
        }
      }
      .active {
        background-color: rgba(255, 136, 34, 0.1);
        border: 1px solid #ff8822;
      }
    }
  }
  .footer {
    position: fixed;
    width: 100%;
    height: 79px;
    bottom: 0;
    background: #fff;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-sizing: border-box;
    padding: 0 18px;
    .left {
      font-size: 14px;
      font-family: PingFang SC-Regular, PingFang SC;
      font-weight: 400;
      color: #333333;
      .num {
        color: #ffa222;
        padding: 0 6px;
        font-weight: 600;
      }
    }
    .right {
      width: 138px;
      height: 42px;
      background: linear-gradient(122deg, #ffa222 0%, #ff8822 100%);
      border-radius: 21px 21px 21px 21px;
      font-size: 16px;
      font-family: PingFang SC-Semibold, PingFang SC;
      font-weight: 600;
      color: #ffffff;
      text-align: center;
      line-height: 42px;
      border-top: 1px solid #e2dfdf;
    }
  }
}
</style>
